<template>
  <div class="login-container">
    <div class="login-box">
      <!-- 头像区域 -->
      <h3 class="title">Login 登录页</h3>

      <!-- 表单区域 -->
      <div class="form-login">
        <!-- 登录名称 -->
        <div class="form-group">
          <label for="username">登录名称</label>
          <input type="text" class="form-control" id="username" placeholder="请输入登录名称" autocomplete="off" v-model.trim="username" />
        </div>
        <!-- 登录密码 -->
        <div class="form-group">
          <label for="password">登录密码</label>
          <input type="password" class="form-control" id="password" placeholder="请输入登录密码" v-model.trim="password" />
        </div>
        <!-- 登录和重置按钮 -->
        <div class="form-group btn-wrap">
          <button type="button" class="reset" @click="reset">重置</button>
          <button type="button" class="login" @click="login">登录</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'MyLogin',
  data() {
    return {
      username: 'admin',
      password: '666666'
    }
  },
  methods: {
    reset() {
      this.username = 'admin'
      this.password = '666666'
    },
    login() {
      if (this.username === 'admin' && this.password === '666666') {
        // 登录成功
        // 1. 存储 token
        localStorage.setItem('token', 'Bearer xxxx')
        // 2. 跳转到后台主页
        this.$router.push('/main')
      } else {
        // 登录失败
        localStorage.removeItem('token')
      }
    }
  }
}
</script>

<style lang="less" scoped>
.login-container {
  height: 100%;
  background: url('@/assets/zm.jpg') no-repeat 0 0;
  background-size: 100% 100%;
  text-align: center;
  .login-box {
    width: 400px;
    height: 250px;
    background-color: #fff;
    border-radius: 3px;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 6px rgba(255, 255, 255, 0.5);
    .title {
      height: 40px;
      line-height: 40px;
    }
    .form-login {
      background-color: #efefef;
      height: calc(100% - 40px);
      width: 100%;
      padding: 50px 20px;
      box-sizing: border-box;
      .form-group {
        margin-bottom: 20px;
        .form-control {
          margin-left: 20px;
        }
      }
      .btn-wrap {
        display: flex;
        justify-content: flex-end;
        .reset {
          margin-right: 20px;
          background-color: rgb(168, 168, 168);
        }
        .login {
          background-color: aqua;
        }
      }
    }
  }
}
</style>
